<?php

class PluginController extends Zend_Controller_Action
{
    function init()
    {
        $this->db = Zend_Registry::get("db");
    }
    
    function preDispatch()
    {
		$this->_helper->layout->disableLayout();
    }
	
	function testRegisterAction()
	{
		$mod = new Sys_LcbApi();
		
		$url = "http://www.lingcaibao.com/channelpub/register";
		
		$data_array = array(
			'username' => '13817958568',
			'userType' => '1'
		);
		
		$r = $mod->CallServer($url, $data_array);
		var_dump($r);die;
		die;
	}
	
	function testLoginAction()
	{
		$mod = new Sys_LcbApi();
		
		$_SESSION['member_info']['cellphone'] = '18918262710';
		
		$mod->CallServerRedirect();
		
		die;
	}
    
    function makeMenuAction()
    {
		$access_token = "ct7kyIW3XwA3_YNU0NToWLPZZ39iy3xGSHpvuw5bZZdgk2JrE2t7_LQfnZAXP_aEOohioAFzZLT1ZhQ0RUrDcPBL4kH_-XCbU_5dFSy1mKEAGDiAEARXU";
		
		$data = ' {
			"button":[
			{
				"type":"view",
				"name":"领彩乐道",
				"url":"http://m.hypercomm.cn"
             },
			{
				"type":"view",
				"name":"会员中心",
				"url":"http://m.hypercomm.cn/members"
             }]
         }';
    	
    	$ch = curl_init();
    	curl_setopt($ch, CURLOPT_URL, "https://api.weixin.qq.com/cgi-bin/menu/create?access_token=".$access_token);
    	curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
    	curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
    	curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
    	curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (compatible; MSIE 5.01; Windows NT 5.0)');
    	curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
    	curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    	$tmpInfo = curl_exec($ch);
    	if (curl_errno($ch)) {
    		echo 'Errno'.curl_error($ch);
    	}
    	curl_close($ch);
    	var_dump($tmpInfo);
    	
    	die;
    }
	
	function memberSessionAction()
	{
		$mod = new Sys_Extensions();
		$mod->FormatArray($_SESSION['member_info']);
		die;
	}
	
	function vimageAction()
	{
		
	}
	
	function testHookAction()
	{
		echo "Test Hook 102.";
		die;
	}
	
	function testDateAction()
	{
		echo date("Y-m-d H:i:s");
		die;
	}
    
    function qrCodeAction()
    {
		include ('phpqrcode/qrlib.php');
    	
		    $tempDir = "images/banners/";

			$codeContents = '123456DEMO';

			// generating
			QRcode::png($codeContents, $tempDir.'007_1.png', QR_ECLEVEL_L, 1);
			QRcode::png($codeContents, $tempDir.'007_2.png', QR_ECLEVEL_L, 2);
			QRcode::png($codeContents, $tempDir.'007_3.png', QR_ECLEVEL_L, 3);
			QRcode::png($codeContents, $tempDir.'007_4.png', QR_ECLEVEL_L, 10);

			// displaying
			echo '<img src="/'.$tempDir.'007_1.png" />';
			echo '<img src="/'.$tempDir.'007_2.png" />';
			echo '<img src="/'.$tempDir.'007_3.png" />';
			echo '<img src="/'.$tempDir.'007_4.png" />'; 
		
    	die;
    }
	
	function wechatShareAction()
	{
		$params = $this->_request->getParams();
		
		if($params['marketId'])
		{
			$marketId = $params['marketId'];
		}else{
			$marketId = 1;
		}
		
		$mod = new Db_Tables_Level3();
		$mod->lcb_market_id = $marketId;
		echo "WechatShare(".Zend_Json::encode($mod->WechatShare()).");";
		die;
	}
	
}